# -*- coding: utf-8 -*-
# Tubedl kurulum aracı
 # Copyright (C) 2007 - 2008
 # Oğuzhan Eroğlu (oguzhan@oguzhaneroglu.com)
 # Mk18(mertk18@gmail.com)
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.

 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.

import os
import shutil
import sys
import glob

if os.environ["USER"] != "root":
	print "Kurulum aracı root olarak çalıştırılmalıdır!"
	sys.exit()

def kur():
	print "Dizinler oluşturuluyor..."
	workdir = "/usr/lib/python2.5/site-packages/tubedl/"
	os.mkdir(workdir)
	dosyalar = glob.glob("*")
	dosyalar.remove("img")
	print "Dosyalar kopyalanıyor..."
	for i in dosyalar:
		shutil.copy(i, workdir)
	print "Çalıştırılabilir dosyalar /usr/bin e atılıyor..."
	shutil.copy("tubedl", "/usr/bin/")
	os.system("cp -rp img %s" % workdir)
	print "İzinler veriliyor..."
	os.chmod("/usr/bin/tubedl", 0777)
	print "Kurulum tamamlandı!"

def kaldir():
	print "Dizinler siliniyor..."
	shutil.rmtree("/usr/lib/python2.5/site-packages/tubedl")
	print "Çalıştırılabilir dosyalar /usr/bin den siliniyor..."
	os.remove("/usr/bin/tubedl")
	print "Tubedl kaldırıldı!"

try:
	if sys.argv[1] == "install":
		try:
			kur()
		except(ImportError):
			print "hata: tubedl zaten kurulu."
	if sys.argv[1] == "remove":
		try:
			kaldir()
		except:
			print "hata: tubedl zaten kurulu değil."
except(IndexError):
	print "Kullanım: setup.py install, setup.py remove"